package com.mongo.service;

import com.mongo.service.impl.LambdaMongoUpdate;
import com.mongo.service.impl.LambdaQuery;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.Collection;
import java.util.List;

/**
 * 提供对mongo的基本增删改查
 * @author xiazhun
 * @create 2022/9/17
 */
public interface MongoMapper<T> extends MongoWrapper{

    /**
     * 获取实体类类型
     * @return  Class
     */
    Class<T> getClazz();

    T insert(T t);

    T queryById(String id);

    T queryOne(Query query);

    T query(LambdaQuery<T> lambdaQuery);

    List<T> list(LambdaQuery<T> lambdaQuery);

    List<T> list(Query query);

    long update(Query query, Update update);

    long update(LambdaMongoUpdate<T> lambdaMongoUpdate);

    long remove(Query query);

    long removeById(String id);

    long removeByIds(Collection<String> collection);

    PageImpl<T> page(Query query, PageRequest pageRequest);

    default PageImpl<T> page(LambdaQuery<T> lambdaQuery, PageRequest pageRequest){
        return page(lambdaQuery.getQuery(),pageRequest);
    }

    long size(Query query);
}
